//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "global.h"
#include "timer.h"
#include "buzz.h"
#include "uart.h"

#if 1
#include "test.h"
#endif
//-----------------------------------------------------------------------------
// SiLabs_Startup() Routine
// ----------------------------------------------------------------------------
// This function is called immediately after reset, before the initialization
// code is run in SILABS_STARTUP.A51 (which runs before main() ). This is a
// useful place to disable the watchdog timer, which is enable by default
// and may trigger before main() in some instances.
//-----------------------------------------------------------------------------
void SiLabs_Startup (void)
{
  // Disable the watchdog here
}

//-----------------------------------------------------------------------------
// main() Routine
// ----------------------------------------------------------------------------
// Note: the software watchdog timer is not disabled by default in this
// example, so a long-running program will reset periodically unless
// the timer is disabled or your program periodically writes to it.
//
// Review the "Watchdog Timer" section under the part family's datasheet
// for details. To find the datasheet, select your part in th
// Simplicity Launcher and click on "Data Sheet".
//-----------------------------------------------------------------------------
int main (void)
{

    //Enter default mode
    enter_DefaultMode_from_RESET();

    user_timer_init();

#if 1

    if ((PCA0PWM & PCA0PWM_ARSEL__BMASK) == 0x00)
    {
        PCA0PWM |= (PCA0PWM_ARSEL__BMASK | PCA0PWM_CLSEL__8_BITS);
    }
    if((PCA0CPM0 & PCA0CPM0_PWM16__8_BIT) == 0x00)
    {
        PCA0CPM0 |= PCA0CPM0_PWM16__8_BIT;
    }

    PCA0CN0_CCF0 = 0;                           // Clear module 0 interrupt flag.

    PCA0CPM0 |= PCA0CPM0_PWM__ENABLED;


    BSP_DISP_EN = BSP_DISP_BC_DRIVEN;   // Display not driven by EFM8

    BSP_BC_EN = BSP_BC_CONNECTED;       // Board controller connected to EFM8
#if 1
    uart_init();
#endif

#endif

#if 0
    test_entrance();
#endif

    while (1)
    {
#if 0 //test
        if (BSP_PB1 == 0)      // If switch pressed
        {
            BSP_LED_G = 0;
            SCON0_TI = 1;
            putchar('a');
        }

        if (BSP_PB0 == 0)      // If switch pressed
        {
            SCON0_TI = 1;
            putchar('B');
        }
#endif
    }
}
